package com.aipanda.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.validation.groups.Default;

import org.hibernate.search.annotations.DateBridge;
import org.hibernate.search.annotations.DocumentId;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.Resolution;
import org.hibernate.search.annotations.Store;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
 * 
 * <b>所属项目:</b>520panda<br/> 
 * <br/>
 * 基类
 * 
 * @param id 主键
 * @param createDate 创建时间
 * @param modifyDate 修改时间
 * 
 * @author wanyuxiang	
 * @currentTime 2014 2014-12-7 下午01:11:59
 */
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE, getterVisibility = JsonAutoDetect.Visibility.NONE, setterVisibility = JsonAutoDetect.Visibility.NONE, isGetterVisibility = JsonAutoDetect.Visibility.NONE, creatorVisibility = JsonAutoDetect.Visibility.NONE)
@MappedSuperclass
public abstract class BaseEntity implements Serializable {
	private static final long serialVersionUID = -67188388306700736L;
	private Long id;
	private Date createDate;
	private Date modifyDate;

	//分组验证
	public interface Save extends Default {
		
	}

	public interface Update extends Default {
		
	}

	@JsonProperty
	@DocumentId//实体类中唯一的属性保存在索引文件中、当进行全文检索时可以用这个唯一的属性来区分索引中其他实体对象，一般使用实体类中的主键属性
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}
	
	/**
	 * Index.TOKENIZED,使用解析器（ananlyzer）去解析该属性域
	 * Index.UN_TOKENIZED,不需要经过解析器解析,整个属性域的值作为索引值
	 * @return
	 */
	@JsonProperty
	@Field(store = Store.YES, index = Index.UN_TOKENIZED)
	@DateBridge(resolution = Resolution.SECOND)
	@Column(name="create_date",nullable = false, updatable = false)
	public Date getCreateDate() {
		return this.createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	@JsonProperty
	@Field(store = Store.YES, index = Index.UN_TOKENIZED)
	@DateBridge(resolution = Resolution.SECOND)
	@Column(name="modify_date",nullable = false)
	public Date getModifyDate() {
		return this.modifyDate;
	}
	
	public void setModifyDate(Date modifyDate) {
		this.modifyDate = modifyDate;
	}
	
	public boolean equals(Object obj) {
		if (obj == null){
			return false;
		}
		if (this == obj){
			return true;
		}
		if (!BaseEntity.class.isAssignableFrom(obj.getClass())){
			return false;
		}
		BaseEntity baseEntity = (BaseEntity) obj;
		return getId() != null ? getId().equals(baseEntity.getId()): false;
	}

	public int hashCode() {
		int i = 17;
		i += (getId() == null ? 0 : getId().hashCode() * 31);
		return i;
	}
}

